<template>
    <div class="user-money-detail">
        <loading-more
            v-model='loading'
            wrapper='.user-money-detail'
            url='account/list'
            @complete='complete = true'
            @finish='setRecords'>
            <div class="user-money-detail-box" v-if='records.length'>
                <ul class="detail__list">
                    <li class="detail__item" v-for='item in records'>
                        <div class="detail__left">
                            <p>{{item.title}}</p>
                            <span>余额:{{item.balance | toYuan}}元</span>
                        </div>
                        <div class="detail__right">
                            <p><template v-if='item.amount>0'>+</template>{{item.amount | toYuan}}</p>
                            <span>{{item.createdAt | dateFormat('YYYY-MM-DD HH:mm:ss')}}</span>
                        </div>
                    </li>
                </ul>
                <p class='user-list-explain' v-if='complete'>以上为全部明细</p>
            </div>
            <loading v-show='loading' :size='15'></loading>
            <p class="page-placeholder" v-if='!records.length && complete'><span>无资金明细</span></p>
        </loading-more>
    </div>
</template>

<script>
    import { Promise } from 'es6-promise'
    import footerBar from '../components/FooterBar.vue'
    import selectGroup from '../components/SelectGroup.vue'
    import selectOption from '../components/SelectOption.vue'
    import radioGroup from '../components/RadioGroup.vue'
    import areaSelect from '../components/AreaSelect.vue'
    import radio from '../components/Radio.vue'
    import loading from '../components/Loading.vue'
    import checkBox from '../components/CheckBox.vue'
    import toolTip from '../components/ToolTip.vue'
    import modal from '../components/Modal.vue'
    import confirm from '../components/Confirm.vue'
    import buttonLoading from '../components/ButtonLoading.vue'
    import pagination from '../components/Pagination.vue'
    import payPassword from '../components/PayPassword.vue'
    import pickerList from '../components/PickerList.vue'
    import loadingMore from '../components/LoadingMore.vue'
    import  { mapGetters, mapActions }  from 'vuex'
    import toYuan from '../filters/filter-toYuan'
    import dateFormat from '../filters/filter-dateFormat'
    import { timeToHours } from '../filters/filter-timeFormat'
    import { addLenderValidation, resetAccountPasswordValidation, operatorEditValidation } from '../validation/validation'
    import { userApi, lenderApi } from '../api/api'
    import { scrollLoading, scrollLoadingOff } from '../utils/utils'
    import moment from 'moment'

    export default {
        components:{
            footerBar,
            selectGroup,
            selectOption,
            radioGroup,
            radio,
            checkBox,
            areaSelect,
            loading,
            toolTip,
            modal,
            confirm,
            buttonLoading,
            pagination,
            payPassword,
            pickerList,
            loadingMore
        },
        filters:{
            toYuan,
            dateFormat,
            timeToHours,
            diffDay(time){
                let now = moment()
                let day = moment(time)
                let diff = day - now
            },

        },
        data() {
            return {
                list:{},
                records:[],
                num:1,
                loading:false,
                complete:false
            }
        },
        computed:{
            ...mapGetters([
                'msgTip',
                'localInfo'
            ]),
            currentPage(){
                if(_.isEmpty(this.listInfo)) return 1
                return this.listInfo.pageNum
            },
            hasUserCount(){
                return !_.isEmpty(this.userCount)
            },
            noEditObject(){
                return _.isEmpty(this.editObject)
            },
            noInvoiceInfo(){
                return _.isEmpty(this.invoiceInfo)
            }
        },
        methods:{
            // actions
            ...mapActions([
                'showLoading',
                'hideLoading',
                'setMsgTip'
            ]),

            // filters
            timestampToDate(timestamp){
                if(!timestamp) return this.placeholder
                return moment(timestamp).format('YYYY-MM-DD')
            },

            // function

            goPhone(){
                this.$router.push({
                    name:'bind-phone'
                })
            },
            goUse(){
                this.$router.push({
                    name:'loan-in-want-use'
                })
            },
            goSuccess(){
                this.$router.push({
                    name:'loan-in-success'
                })
            },
            test(){
                console.log(1)
            },
            goPay(){
                this.payStatus = true
                console.log(1)
            },
            goDetail(item){
                this.$router.push({
                    name:'user-detail',
                    params:{
                        id:item.userId,
                    }
                })
            },
            setRecords(records){
                this.records = records
            },
        },
        created(){
        }
    }
</script>

<style lang="scss">
    @import "../sass/variables";
    @import "../sass/extends";
    @import "../sass/mixins";
    .user-money-detail{
        .page-placeholder{
            position: absolute;
            top:0;
            left:0;
            right:0;
        }
        padding-bottom: 40px;
        .detail__item{
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: #fff;
            padding: 20px 24px 16px 24px;
            position: relative;
            &:after{
                content:'';
                border-top: 1px solid $sectionColor;
                position: absolute;
                bottom:0;
                left:16px;
                right:16px;
            }
            &:last-child{
                &:after{
                    display: none;
                }
            }
        }
        .detail__left{
            p{
                @extend %font-subhead;
                color:$importColor;
            }
            span{
                @extend %font-caption;
                display: block;
            }
        }
        .detail__right{
            text-align: right;
            p{
                @extend %font-title;
                color:$importColor;
            }
            span{
                @extend %font-caption;
                display: block;
            }
        }
    }

</style>
